//
//  Primer_Closure_escaping_DemoVC.swift
//  APSwift
//
//  Created by jianbo.pei on 2024/1/1.
//

import UIKit

//*********1、闭包作为属性
class CJLTeacher {
    //定义一个闭包属性
    var complitionHandler: ((Int)->Void)?
    
    //函数参数使用@escaping修饰，表示允许函数返回之后调用
    func makeIncrementer(amount: Int, handler: @escaping (Int)->Void){
        var runningTotal = 0
        runningTotal += amount
        //赋值给属性
        self.complitionHandler = handler
    }

    func doSomething(){
        self.makeIncrementer(amount: 10) {
            print($0)
        }
    }

    deinit {
        print("CJLTeacher deinit")
    }
}
////使用
//var t = CJLTeacher()
//t.doSomething()
//t.complitionHandler?(10)
//
//<!--打印结果-->
//10

class Primer_Closure_escaping_DemoVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        test1()
    }
    
    
    private func test1() {
        //使用
        var t = CJLTeacher()
        t.doSomething()
        t.complitionHandler?(10)
    }

}
